﻿using System;
using System.Collections.Generic;
using Assist;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;
using YArchitech.Revit;
using YArchitech.Revit.RevitExtension;

namespace YJKFamilyLibDataManager
{
	public class DbGeometry
	{
		public static bool LessThan(double val1, double val2)
		{
			return val1 - val2 < -1E-09;
		}

		public static bool GreaterThan(double val1, double val2)
		{
			return val1 - val2 > 1E-09;
		}

		public static bool IsEqual(double val1, double val2)
		{
			return !DbGeometry.LessThan(val1, val2) && !DbGeometry.LessThan(val2, val1);
		}

		public static bool Lessthan_Or_Equal(double val1, double val2)
		{
			return !DbGeometry.GreaterThan(val1, val2);
		}

		public static bool Greaterthan_Or_Equal(double val1, double val2)
		{
			return !DbGeometry.LessThan(val1, val2);
		}

		public static bool IsParallel(XYZ a, XYZ b)
		{
			double num = a.AngleTo(b);
			return 1E-09 > num || DbGeometry.IsEqual(num, Math.PI);
		}

		public static bool IsVertical(XYZ a, XYZ b)
		{
			double val = a.AngleTo(b);
			return DbGeometry.IsEqual(val, Math.PI*.5);
		}

		public static XYZ RotateTo(XYZ List, double angle, XYZ axis)
		{
			Transform transform = RevitVersionFuncs.CreateRotationAtPoint(axis, angle, new XYZ(0.0, 0.0, 0.0));
			return DbGeometry.TransformPoint(List, transform);
		}

		public static XYZ CalculateFootPoint(Line line, XYZ point)
		{
			XYZ hyendPoint = line.GetEndPoint(0);
			XYZ hyendPoint2 = line.GetEndPoint(1);
			return DbGeometry.CalculateFootPoint(hyendPoint, hyendPoint2, point);
		}

		public static XYZ CalculateFootPoint(XYZ ptStart, XYZ ptEnd, XYZ point)
		{
			double num = Math.Sqrt((ptEnd.X - ptStart.X) * (ptEnd.X - ptStart.X) + (ptEnd.Y - ptStart.Y) * (ptEnd.Y - ptStart.Y) + (ptEnd.Z - ptStart.Z) * (ptEnd.Z - ptStart.Z));
			double num2 = (ptEnd.X - ptStart.X) * (point.X - ptStart.X) + (ptEnd.Y - ptStart.Y) * (point.Y - ptStart.Y) + (ptEnd.Z - ptStart.Z) * (point.Z - ptStart.Z);
			num = num2 / (num * num);
			double num3 = ptStart.X + (ptEnd.X - ptStart.X) * num;
			double num4 = ptStart.Y + (ptEnd.Y - ptStart.Y) * num;
			double num5 = ptStart.Z + (ptEnd.Z - ptStart.Z) * num;
			return new XYZ(num3, num4, num5);
		}

		public static XYZ CalculateFootPoint(Arc arc, XYZ point)
		{
			XYZ center = arc.Center;
			XYZ hyendPoint = arc.GetEndPoint(0);
			XYZ hyendPoint2 = arc.GetEndPoint(1);
			return DbGeometry.CalculateFootPoint(hyendPoint, hyendPoint2, center, point);
		}

		public static XYZ CalculateFootPoint(XYZ ptStart, XYZ ptEnd, XYZ ptCenter, XYZ point)
		{
			double num = ptCenter.DistanceTo(ptStart);
			XYZ xyz = new XYZ(point.X, point.Y, ptCenter.Z);
			XYZ xyz2 = xyz - ptCenter;
			xyz2 = xyz2.Normalize() * num;
			return ptCenter + xyz2;
		}

		public static bool PointAtLineLeft(XYZ pt, XYZ ptStart, XYZ ptEnd)
		{
			double num = ptEnd.Y - ptStart.Y;
			double num2 = ptStart.X - ptEnd.X;
			double num3 = ptEnd.X * ptStart.Y - ptStart.X * ptEnd.Y;
			double num4 = num * pt.X + num2 * pt.Y + num3;
			return num4 < 0.0;
		}

		public static XYZ TransformPoint(XYZ point, Transform transform)
		{
			double x = point.X;
			double y = point.Y;
			double z = point.Z;
			XYZ xyz = transform.get_Basis(0);
			XYZ xyz2 = transform.get_Basis(1);
			XYZ xyz3 = transform.get_Basis(2);
			XYZ origin = transform.Origin;
			double num = x * xyz.X + y * xyz2.X + z * xyz3.X + origin.X;
			double num2 = x * xyz.Y + y * xyz2.Y + z * xyz3.Y + origin.Y;
			double num3 = x * xyz.Z + y * xyz2.Z + z * xyz3.Z + origin.Z;
			return new XYZ(num, num2, num3);
		}

		public static BoundingBoxUV CalculateBoundingBox2D(Line line)
		{
			XYZ hyendPoint = line.GetEndPoint(0);
			XYZ hyendPoint2 = line.GetEndPoint(1);
			double x = hyendPoint.X;
			double x2 = hyendPoint2.X;
			double y = hyendPoint.Y;
			double y2 = hyendPoint2.Y;
			if (x > x2)
			{
				x = hyendPoint2.X;
				x2 = hyendPoint.X;
			}
			if (y > y2)
			{
				y = hyendPoint2.Y;
				y2 = hyendPoint.Y;
			}
			return new BoundingBoxUV(x, y, x2, y2);
		}

		public static void GetArcAngles(Arc arc, ref double startAngle, ref double endAngle)
		{
			XYZ hyendPoint = arc.GetEndPoint(0);
			XYZ hyendPoint2 = arc.GetEndPoint(1);
			XYZ center = arc.Center;
			startAngle = XYZ.BasisX.AngleOnPlaneTo(hyendPoint - center, XYZ.BasisZ);
			endAngle = XYZ.BasisX.AngleOnPlaneTo(hyendPoint2 - center, XYZ.BasisZ);
			if (DbGeometry.IsEqual(arc.Normal.Z, -1.0))
			{
				endAngle = (double)((float)XYZ.BasisX.AngleOnPlaneTo(hyendPoint - center, XYZ.BasisZ));
				startAngle = (double)((float)XYZ.BasisX.AngleOnPlaneTo(hyendPoint2 - center, XYZ.BasisZ));
			}
			if (startAngle > endAngle)
			{
				startAngle -= Math.PI*2;
			}
		}

		public static BoundingBoxUV CalculateBoundingBox2D(Arc arc)
		{
			XYZ hyendPoint = arc.GetEndPoint(0);
			XYZ hyendPoint2 = arc.GetEndPoint(1);
			XYZ center = arc.Center;
			double radius = arc.Radius;
			double num = hyendPoint.X;
			double num2 = hyendPoint2.X;
			double num3 = hyendPoint.Y;
			double num4 = hyendPoint2.Y;
			if (num > num2)
			{
				num = hyendPoint2.X;
				num2 = hyendPoint.X;
			}
			if (num3 > num4)
			{
				num3 = hyendPoint2.Y;
				num4 = hyendPoint.Y;
			}
			Line line = YJKLineEx.YJKGetUnBound(center, XYZ.BasisX);
			IntersectionResultArray intersectionResultArray;
			SetComparisonResult setComparisonResult = arc.Intersect(line, out intersectionResultArray);
			if (setComparisonResult == SetComparisonResult.Overlap && intersectionResultArray.Size > 0)
			{
				num2 = center.X + radius;
			}
			Line line2 = YJKLineEx.YJKGetUnBound(center, -XYZ.BasisX);
			IntersectionResultArray intersectionResultArray2;
			SetComparisonResult setComparisonResult2 = arc.Intersect(line2, out intersectionResultArray2);
            if ((int)setComparisonResult2 == 8 && intersectionResultArray2.Size > 0)
			{
				num = center.X - radius;
			}
			Line line3 = YJKLineEx.YJKGetUnBound(center, XYZ.BasisY);
			IntersectionResultArray intersectionResultArray3;
			SetComparisonResult setComparisonResult3 = arc.Intersect(line3, out intersectionResultArray3);
            if ((int)setComparisonResult3 == 8 && intersectionResultArray3.Size > 0)
			{
				num4 = center.Y + radius;
			}
			Line line4 = YJKLineEx.YJKGetUnBound(center, -XYZ.BasisY);
			IntersectionResultArray intersectionResultArray4;
			SetComparisonResult setComparisonResult4 = arc.Intersect(line4, out intersectionResultArray4);
            if ((int)setComparisonResult4 == 8 && intersectionResultArray4.Size > 0)
			{
				num3 = center.Y - radius;
			}
			return new BoundingBoxUV(num, num3, num2, num4);
		}

		public static BoundingBoxUV BoundingBoxesMerge(BoundingBoxUV box1, BoundingBoxUV box2)
		{
			BoundingBoxUV boundingBoxUV = new BoundingBoxUV();
			double u = box1.Min.U;
			double v = box1.Min.V;
			double u2 = box1.Max.U;
			double v2 = box1.Max.V;
			UV min = box2.Min;
			UV max = box2.Max;
			if (min.U < u)
			{
				u = min.U;
			}
			if (min.V < v)
			{
				v = min.V;
			}
			boundingBoxUV.Min = new UV(u, v);
			if (max.U > u2)
			{
				u2 = max.U;
			}
			if (max.V > v2)
			{
				v2 = max.V;
			}
			boundingBoxUV.Max = new UV(u2, v2);
			return boundingBoxUV;
		}

		public static BoundingBoxXYZ BoundingBoxesMerge(BoundingBoxXYZ box1, BoundingBoxXYZ box2)
		{
			BoundingBoxXYZ boundingBoxXYZ = new BoundingBoxXYZ();
			double x = box1.Min.X;
			double y = box1.Min.Y;
			double z = box1.Min.Z;
			double x2 = box1.Max.X;
			double y2 = box1.Max.Y;
			double z2 = box1.Max.Z;
			XYZ min = box2.Min;
			XYZ max = box2.Max;
			if (min.X < x)
			{
				x = min.X;
			}
			if (min.Y < y)
			{
				y = min.Y;
			}
			if (min.Z < z)
			{
				z = min.Z;
			}
			boundingBoxXYZ.Min = new XYZ(x, y, z);
			if (max.X > x2)
			{
				x2 = max.X;
			}
			if (max.Y > y2)
			{
				y2 = max.Y;
			}
			if (max.Z > z2)
			{
				z2 = max.Z;
			}
			boundingBoxXYZ.Max = new XYZ(x2, y2, z2);
			return boundingBoxXYZ;
		}

		public static XYZ CalculatMidPoint(XYZ ptStart, XYZ ptEnd)
		{
			XYZ xyz = ptEnd - ptStart;
			return ptStart + xyz / 2.0;
		}

		public static XYZ CalculatMidPoint(Line line)
		{
			XYZ hyendPoint = line.GetEndPoint(0);
			XYZ hyendPoint2 = line.GetEndPoint(1);
			return DbGeometry.CalculatMidPoint(hyendPoint, hyendPoint2);
		}

		public static XYZ CalculatMidPoint(XYZ ptStart, XYZ ptEnd, XYZ ptCenter, XYZ normal)
		{
			if (normal.Z < 0.0)
			{
				XYZ xyz = ptStart;
				ptStart = ptEnd;
				ptEnd = xyz;
			}
			XYZ xyz2 = ptStart - ptCenter;
			double length = xyz2.GetLength();
			xyz2 = xyz2.Normalize();
			double num = XYZ.BasisX.AngleOnPlaneTo(ptStart - ptCenter, XYZ.BasisZ);
			double num2 = XYZ.BasisX.AngleOnPlaneTo(ptEnd - ptCenter, XYZ.BasisZ);
			if (num > num2)
			{
				num -= Math.PI*2;
			}
			double angle = (num2 - num) / 2.0;
			XYZ xyz3 = DbGeometry.RotateTo(xyz2, angle, XYZ.BasisZ).Normalize();
			return ptCenter + xyz3 * length;
		}

		public static XYZ CalculatMidPoint(Arc arc)
		{
			XYZ hyendPoint = arc.GetEndPoint(0);
			XYZ center = arc.Center;
			XYZ list = (hyendPoint - center).Normalize();
			double radius = arc.Radius;
			double num = arc.Length / radius / 2.0;
			XYZ xyz = DbGeometry.RotateTo(list, num, XYZ.BasisZ).Normalize();
			if (DbGeometry.IsEqual(arc.Normal.Z, -1.0))
			{
				xyz = DbGeometry.RotateTo(list, -num, XYZ.BasisZ).Normalize();
			}
			return center + xyz * radius;
		}

		public static Line OffsetLine(Line line, double offset)
		{
			XYZ hyendPoint = line.GetEndPoint(0);
			XYZ hyendPoint2 = line.GetEndPoint(1);
			XYZ direction = line.Direction;
			XYZ xyz = DbGeometry.RotateTo(direction, Math.PI*.5, XYZ.BasisZ) * offset;
			XYZ startPoint = hyendPoint + xyz;
			XYZ endPoint = hyendPoint2 + xyz;
			return YJKLineEx.YJKGetBound(startPoint, endPoint);
		}

		public static Arc OffsetArc(Application app, Arc arc, double offset)
		{
			if (arc.Normal.Z > 0.0)
			{
				offset = -offset;
			}
			XYZ hyendPoint = arc.GetEndPoint(0);
			XYZ hyendPoint2 = arc.GetEndPoint(1);
			XYZ center = arc.Center;
			XYZ xyz = DbGeometry.CalculatMidPoint(arc);
			double radius = arc.Radius;
			double num = radius + offset;
			XYZ xyz2 = (hyendPoint - center).Normalize() * num;
			XYZ xyz3 = (hyendPoint2 - center).Normalize() * num;
			XYZ xyz4 = (xyz - center).Normalize() * num;
			XYZ startPnt = center + xyz2;
			XYZ endPnt = center + xyz3;
			XYZ radianPnt = center + xyz4;
			return app.CreatYJKArc(startPnt, endPnt, radianPnt);
		}

		public static double formatAngle(double angle)
		{
			int num = (int)(angle / Math.PI*2);
			double num2 = angle - (double)num * Math.PI*2;
			if (num2 < 0.0)
			{
				num2 += Math.PI*2;
			}
			return num2;
		}

		public static double getAngle(XYZ ptCenter, XYZ ptOut)
		{
			XYZ xyz = ptOut - ptCenter;
			double angle = XYZ.BasisX.AngleOnPlaneTo(xyz, XYZ.BasisZ);
			return DbGeometry.formatAngle(angle);
		}

		public static double BetweenTheAngles(double dSAngle, double dEAngle, bool range2PI)
		{
			dSAngle = DbGeometry.formatAngle(dSAngle);
			dEAngle = DbGeometry.formatAngle(dEAngle);
			if (Math.Abs(dEAngle - dSAngle) < 1E-05)
			{
				return 0.0;
			}
			if (range2PI && dEAngle < dSAngle)
			{
				dEAngle += Math.PI*2;
			}
			return dEAngle - dSAngle;
		}

		public static double IntersectionAngle(double dSAngle, double dEAngle)
		{
			dSAngle = DbGeometry.formatAngle(dSAngle);
			dEAngle = DbGeometry.formatAngle(dEAngle);
			double num = DbGeometry.formatAngle(Math.Abs(dSAngle - dEAngle));
			if (num > Math.PI)
			{
				num = Math.PI*2 - num;
			}
			return num;
		}

		public static double GetBulge(XYZ SP, XYZ EP, XYZ CenterPt, bool isAnticlockwise)
		{
			XYZ xyz = SP;
			XYZ xyz2 = EP;
			if (!isAnticlockwise)
			{
				xyz = EP;
				xyz2 = SP;
			}
			double num = xyz.DistanceTo(CenterPt);
			double num2 = xyz.DistanceTo(xyz2) / 2.0;
			double num3 = num - Math.Sqrt(num * num - num2 * num2);
			double angle = DbGeometry.getAngle(CenterPt, xyz);
			double angle2 = DbGeometry.getAngle(CenterPt, xyz2);
			double num4 = DbGeometry.BetweenTheAngles(angle, angle2, true);
			if (DbGeometry.IsEqual(num4, Math.PI))
			{
				num3 = num2;
			}
			else if (DbGeometry.LessThan(Math.PI, num4))
			{
				num3 = num * 2.0 - num3;
			}
			double num5 = num3 / num2;
			if (!isAnticlockwise)
			{
				num5 *= -1.0;
			}
			return num5;
		}

		public static void GetRadiusWithBulge(XYZ SP, XYZ EP, double dBulge, ref double dRadius)
		{
			if (DbGeometry.IsEqual(dBulge, 1.0))
			{
				dRadius = SP.DistanceTo(EP) / 2.0;
				return;
			}
			double num = SP.DistanceTo(EP) / 2.0;
			double num2 = Math.Abs(dBulge) * num;
			dRadius = (num * num + num2 * num2) / (num2 * 2.0);
		}

		public static void GetCenterWithBulge(XYZ SP, XYZ EP, double dBulge, ref XYZ ptCenter)
		{
			if (DbGeometry.IsEqual(dBulge, 1.0))
			{
				ptCenter = DbGeometry.CalculatMidPoint(SP, EP);
				return;
			}
			double num = SP.DistanceTo(EP) / 2.0;
			double num2 = Math.Abs(dBulge) * num;
			double num3 = (num * num + num2 * num2) / (num2 * 2.0);
			XYZ xyz = DbGeometry.CalculatMidPoint(SP, EP);
			XYZ xyz2 = (EP - SP).Normalize();
			if (dBulge > 0.0)
			{
				xyz2 = DbGeometry.RotateTo(xyz2, Math.PI*.5, XYZ.BasisZ);
				xyz2 *= num3 - num2;
				ptCenter = xyz + xyz2;
				return;
			}
			xyz2 = DbGeometry.RotateTo(xyz2, -Math.PI*.5, XYZ.BasisZ);
			xyz2 *= num3 - num2;
			ptCenter = xyz + xyz2;
		}

		public static void GetArcInfoWithBulge(XYZ SP, XYZ EP, double dBulge, ref XYZ ptCenter, ref double dRadius, ref double dSAngle, ref double dEAngle)
		{
			DbGeometry.GetCenterWithBulge(SP, EP, dBulge, ref ptCenter);
			dRadius = SP.DistanceTo(ptCenter);
			Math.Atan(1.0 / Math.Abs(dBulge));
			if (dBulge > 0.0)
			{
				dSAngle = ptCenter.AngleOnPlaneTo(SP, XYZ.BasisZ);
				dEAngle = ptCenter.AngleOnPlaneTo(EP, XYZ.BasisZ);
				return;
			}
			dSAngle = ptCenter.AngleOnPlaneTo(EP, XYZ.BasisZ);
			dEAngle = ptCenter.AngleOnPlaneTo(SP, XYZ.BasisZ);
		}

		public static bool Is_Points_Collinear(XYZ pt1, XYZ pt2, XYZ pt3)
		{
			double num = pt2.X - pt1.X;
			double num2 = pt2.Y - pt1.Y;
			double num3 = pt2.Z - pt1.Z;
			double num4 = pt3.X - pt1.X;
			double num5 = pt3.Y - pt1.Y;
			double num6 = pt3.Z - pt1.Z;
			double num7 = num2 * num6 - num5 * num3;
			double num8 = num4 * num3 - num * num6;
			double num9 = num * num5 - num4 * num2;
			return DbGeometry.IsEqual(num7 * num7 + num8 * num8 + num9 * num9, 0.0);
		}

		public static bool Is_Point_OnSegment(XYZ ptSOfLine, XYZ ptEOfLine, XYZ pt)
		{
			double x = ptSOfLine.X;
			double y = ptSOfLine.Y;
			double z = ptSOfLine.Z;
			double x2 = ptEOfLine.X;
			double y2 = ptEOfLine.Y;
			double z2 = ptEOfLine.Z;
			return ((DbGeometry.Lessthan_Or_Equal(x, pt.X) && DbGeometry.Lessthan_Or_Equal(pt.X, x2)) || (DbGeometry.Lessthan_Or_Equal(x2, pt.X) && DbGeometry.Lessthan_Or_Equal(pt.X, x))) && ((DbGeometry.Lessthan_Or_Equal(y, pt.Y) && DbGeometry.Lessthan_Or_Equal(pt.Y, y2)) || (DbGeometry.Lessthan_Or_Equal(y2, pt.Y) && DbGeometry.Lessthan_Or_Equal(pt.Y, y))) && ((DbGeometry.Lessthan_Or_Equal(z, pt.Z) && DbGeometry.Lessthan_Or_Equal(pt.Z, z2)) || (DbGeometry.Lessthan_Or_Equal(z2, pt.Z) && DbGeometry.Lessthan_Or_Equal(pt.Z, z))) && DbGeometry.Is_Points_Collinear(ptSOfLine, ptEOfLine, pt);
		}

		public static bool Is_Point_OnSegment(XYZ ptSOfArc, XYZ ptEOfArc, XYZ ptCenterOfArc, XYZ normal, XYZ pt)
		{
			if (normal.Z < 0.0)
			{
				XYZ xyz = ptSOfArc;
				ptSOfArc = ptEOfArc;
				ptEOfArc = xyz;
			}
			double val = ptSOfArc.DistanceTo(ptCenterOfArc);
			double val2 = ptEOfArc.DistanceTo(ptCenterOfArc);
			if (!DbGeometry.IsEqual(val, val2))
			{
				return false;
			}
			double val3 = pt.DistanceTo(ptCenterOfArc);
			if (!DbGeometry.IsEqual(val, val3))
			{
				return false;
			}
			double angle = DbGeometry.getAngle(ptCenterOfArc, ptSOfArc);
			double angle2 = DbGeometry.getAngle(ptCenterOfArc, pt);
			double angle3 = DbGeometry.getAngle(ptCenterOfArc, pt);
			double num = DbGeometry.BetweenTheAngles(angle, angle2, true);
			double num2 = DbGeometry.BetweenTheAngles(angle2, angle3, true);
			double val4 = DbGeometry.BetweenTheAngles(angle, angle3, true);
			return DbGeometry.IsEqual(val4, num + num2);
		}

		protected static List<Curve> ExtendEndsWithCurve(Curve curve, Application revitApp)
		{
			List<Curve> list = new List<Curve>();
			if (!curve.IsBound)
			{
				list.Add(curve);
				return list;
			}
			Line line = curve as Line;
			if (null != line)
			{
				XYZ hyendPoint = line.GetEndPoint(0);
				XYZ hyendPoint2 = line.GetEndPoint(1);
				Line item = revitApp.CreatYJKLine(hyendPoint, hyendPoint2 - hyendPoint, false);
				list.Add(item);
				return list;
			}
			Arc arc = curve as Arc;
			if (null != arc)
			{
				XYZ center = arc.Center;
				double radius = arc.Radius;
				XYZ xyz = center + XYZ.BasisX * radius;
				XYZ radianPnt = center + XYZ.BasisY * radius;
				XYZ xyz2 = center + -XYZ.BasisX * radius;
				XYZ radianPnt2 = center + -XYZ.BasisY * radius;
				Arc item2 = revitApp.CreatYJKArc(xyz, xyz2, radianPnt);
				list.Add(item2);
				Arc item3 = revitApp.CreatYJKArc(xyz2, xyz, radianPnt2);
				list.Add(item3);
				return list;
			}
			return list;
		}

		public static XYZ IntersectWithTwoCurves(Curve curve1, Curve curve2, XYZ curNode, bool extendCurve1, bool extendCurve2, Application revitApp)
		{
			List<Curve> list = new List<Curve>();
			if (extendCurve1)
			{
				list = DbGeometry.ExtendEndsWithCurve(curve1, revitApp);
			}
			else
			{
				list.Add(curve1);
			}
			List<Curve> list2 = new List<Curve>();
			if (extendCurve2)
			{
				list2 = DbGeometry.ExtendEndsWithCurve(curve2, revitApp);
			}
			else
			{
				list2.Add(curve2);
			}
			List<XYZ> list3 = new List<XYZ>();
			foreach (Curve curve3 in list)
			{
				foreach (Curve curve4 in list2)
				{
					IntersectionResultArray intersectionResultArray;
					SetComparisonResult setComparisonResult = curve3.Intersect(curve4, out intersectionResultArray);
					if (setComparisonResult == SetComparisonResult.Overlap)
					{
						foreach (object obj in intersectionResultArray)
						{
							IntersectionResult intersectionResult = (IntersectionResult)obj;
							list3.Add(intersectionResult.XYZPoint);
						}
					}
				}
			}
			double num = double.MaxValue;
			XYZ result = null;
			foreach (XYZ xyz in list3)
			{
				double num2 = curNode.DistanceTo(xyz);
				if (num2 < num)
				{
					num = num2;
					result = xyz;
				}
			}
			return result;
		}

		public static DbGeometry.OverlapType IsOverlapOfTwoLine(XYZ ptS1, XYZ ptE1, XYZ ptS2, XYZ ptE2, ref XYZ ptS, ref XYZ ptE)
		{
			if ((ptS1.IsAlmostEqualTo(ptS2) && ptE1.IsAlmostEqualTo(ptE2)) || (ptS1.IsAlmostEqualTo(ptE2) && ptE1.IsAlmostEqualTo(ptS2)))
			{
				ptS = ptS1;
				ptE = ptE1;
				return DbGeometry.OverlapType._OT_Equality;
			}
			if (DbGeometry.Is_Point_OnSegment(ptS1, ptE1, ptS2) && DbGeometry.Is_Point_OnSegment(ptS1, ptE1, ptE2))
			{
				ptS = ptS2;
				ptE = ptE2;
				return DbGeometry.OverlapType._OT_FirstIncludeSecond;
			}
			if (DbGeometry.Is_Point_OnSegment(ptS2, ptE2, ptS1) && DbGeometry.Is_Point_OnSegment(ptS2, ptE2, ptE1))
			{
				ptS = ptS1;
				ptE = ptE1;
				return DbGeometry.OverlapType._OT_SecondIncludeFirst;
			}
			if (DbGeometry.Is_Point_OnSegment(ptS1, ptE1, ptS2))
			{
				if (DbGeometry.Is_Point_OnSegment(ptS2, ptE2, ptS1))
				{
					if (!ptS2.IsAlmostEqualTo(ptS1))
					{
						ptS = ptS2;
						ptE = ptS1;
						return DbGeometry.OverlapType._OT_Part;
					}
				}
				else if (DbGeometry.Is_Point_OnSegment(ptS2, ptE2, ptE1) && !ptS2.IsAlmostEqualTo(ptE1))
				{
					ptS = ptS2;
					ptE = ptE1;
					return DbGeometry.OverlapType._OT_Part;
				}
			}
			else if (DbGeometry.Is_Point_OnSegment(ptS1, ptE1, ptE2))
			{
				if (DbGeometry.Is_Point_OnSegment(ptS2, ptE2, ptS1))
				{
					if (!ptE2.IsAlmostEqualTo(ptS1))
					{
						ptS = ptE2;
						ptE = ptS1;
						return DbGeometry.OverlapType._OT_Part;
					}
				}
				else if (DbGeometry.Is_Point_OnSegment(ptS2, ptE2, ptE1) && !ptE2.IsAlmostEqualTo(ptE1))
				{
					ptS = ptE2;
					ptE = ptE1;
					return DbGeometry.OverlapType._OT_Part;
				}
			}
			return DbGeometry.OverlapType._OT_None;
		}

		private static bool IsCoverAngle(double sAngle, double eAngle, double testAngle)
		{
			double val = DbGeometry.BetweenTheAngles(sAngle, eAngle, true);
			double num = DbGeometry.BetweenTheAngles(sAngle, testAngle, true);
			double num2 = DbGeometry.BetweenTheAngles(testAngle, eAngle, true);
			return DbGeometry.IsEqual(val, num + num2);
		}

		public static DbGeometry.OverlapType IsOverlapOfTwoArc(XYZ ptS1, XYZ ptE1, XYZ ptCenter1, XYZ ptS2, XYZ ptE2, XYZ ptCenter2, ref XYZ ptS, ref XYZ ptE)
		{
			if (!ptCenter1.IsAlmostEqualTo(ptCenter2))
			{
				return DbGeometry.OverlapType._OT_None;
			}
			double val = ptS1.DistanceTo(ptCenter1);
			double val2 = ptS2.DistanceTo(ptCenter2);
			if (!DbGeometry.IsEqual(val, val2))
			{
				return DbGeometry.OverlapType._OT_None;
			}
			double angle = DbGeometry.getAngle(ptCenter1, ptS1);
			double angle2 = DbGeometry.getAngle(ptCenter1, ptE1);
			double angle3 = DbGeometry.getAngle(ptCenter2, ptS2);
			double angle4 = DbGeometry.getAngle(ptCenter2, ptE2);
			if (DbGeometry.IsEqual(angle, angle3) && DbGeometry.IsEqual(angle2, angle4))
			{
				ptS = ptS1;
				ptE = ptE1;
				return DbGeometry.OverlapType._OT_Equality;
			}
			if (DbGeometry.IsEqual(angle, angle4) && DbGeometry.IsEqual(angle2, angle3))
			{
				return DbGeometry.OverlapType._OT_None;
			}
			if (DbGeometry.IsCoverAngle(angle, angle2, angle3) && DbGeometry.IsCoverAngle(angle, angle2, angle4))
			{
				ptS = ptS2;
				ptE = ptE2;
				return DbGeometry.OverlapType._OT_FirstIncludeSecond;
			}
			if (DbGeometry.IsCoverAngle(angle3, angle4, angle) && DbGeometry.IsCoverAngle(angle3, angle4, angle2))
			{
				ptS = ptS1;
				ptE = ptE1;
				return DbGeometry.OverlapType._OT_SecondIncludeFirst;
			}
			if (DbGeometry.IsCoverAngle(angle3, angle4, angle))
			{
				ptS = ptS1;
				ptE = ptE2;
				return DbGeometry.OverlapType._OT_Part;
			}
			if (DbGeometry.IsCoverAngle(angle, angle2, angle3))
			{
				ptS = ptS2;
				ptE = ptE1;
				return DbGeometry.OverlapType._OT_Part;
			}
			return DbGeometry.OverlapType._OT_None;
		}

		private static bool IsOverlap(XYZ ptS1, XYZ ptE1, double bugle1, XYZ ptS2, XYZ ptE2, double bugle2)
		{
			if (DbGeometry.IsEqual(bugle1, 0.0) && DbGeometry.IsEqual(bugle2, 0.0))
			{
				if (ptS1.IsAlmostEqualTo(ptE2, 0.0001) && ptE1.IsAlmostEqualTo(ptS2, 0.0001))
				{
					return true;
				}
			}
			else if (!DbGeometry.IsEqual(bugle1, 0.0) && !DbGeometry.IsEqual(bugle2, 0.0) && ptS1.IsAlmostEqualTo(ptE2, 0.0001) && ptE1.IsAlmostEqualTo(ptS2, 0.0001) && DbGeometry.IsEqual(bugle1, -bugle2))
			{
				return true;
			}
			return false;
		}

		public const double _epsDouble = 1E-09;

		public const double _epsPoint = 0.0001;

		public const double _epsAngle = 0.0001;

		public enum OverlapType
		{
			_OT_None,
			_OT_Equality,
			_OT_FirstIncludeSecond,
			_OT_SecondIncludeFirst,
			_OT_Part
		}
	}
}
